package signBean;

import java.sql.*;
import java.util.*;
public class Manager {
	public String count;
	public String password;
	public String name;	
	public String id;
	 public String auth;
	public String address;
	public String age;
	public String userview;
	public String createtime;
	public String gender;
	public String choseclassid;
	public String email;
	public String educationbackground;
	public String graduateuniversity;
	public String phone;
	public String mobile;
    public String 	qq;


     public String 	question;


	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCount() {
		return count;
	}

	public void setCount(String count) {
		this.count = count;
	}

	public Connection conn(){
		Connection conn=null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			conn=DriverManager.getConnection("jdbc:mysql://localhost/sign?useUnicode=true&characterEncoding=UTF8","root","");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
		
		
		
	}
	
	public String check(String name,String pass){
		Connection con=conn();
		Statement sta=null;
		boolean ff=false;
		try {
			sta = con.createStatement();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			ResultSet s=sta.executeQuery("select * from a_user where uname='"+name+"' and password='"+pass+"'");
			if(s.next()){
				id=s.getString("id");
				
				
				
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return id;
		
	}
	public boolean checkUserName(String name) throws SQLException{
		
         Connection con=conn();
		boolean ff=false;
		Statement sta=con.createStatement();
		ResultSet rs=sta.executeQuery("select * from a_user where uname='"+name+"'");
		if(rs.next()){
			ff=true;
		}
		
		return ff;
		
	}
	public List checkIds(String name,String pass) throws SQLException{
		List list =new ArrayList();
		Connection con=conn();
		
		Statement sta=con.createStatement();
		ResultSet rs=sta.executeQuery("select * from a_user where uname='"+name+"' and password='"+pass+"'");
		while(rs.next()){
			list.add(rs.getString("id"));
			list.add(rs.getString("auth"));
			list.add(rs.getString("name"));
			
			
		}
		return list;
	}
	
	public boolean checkUser(String name){
		Connection con=conn();
		Statement sta=null;
		boolean ff=false;
		try {
			sta = con.createStatement();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			ResultSet s=sta.executeQuery("select * from zhuce1 where name='"+name+"'");
			if(s.next()){
				
				ff=true;
				
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return ff;
		
	}
	
	
	
	
	
	
	
	
	
  public boolean delete(String ff) throws SQLException{
	  Connection con=conn();
		
		Statement sta=con.createStatement();
		boolean fff=sta.execute("delete from  zhuce1 where id='"+ff+"'");
		  System.out.print("dsfdsf");
		return fff;
	  
  }
	public List getAllBook() throws SQLException{
		
		List list =new ArrayList();
		Connection con=conn();
		Statement sta=con.createStatement();
		ResultSet rs = sta.executeQuery("select * from  a_signup where userview=0");
		
		while(rs.next()){
			
			String id=rs.getString("id");
			String name=rs.getString("name");
		    String createtime=rs.getString("createtime");
			String gender=rs.getString("gender");
			String userview=rs.getString("userview");
			Manager a=new Manager();
			a.setName(name);
			a.setId(id);
			a.setCreatetime(createtime);
			a.setGender(gender);
			a.setUserview(userview);
			a.setId(id);
		    list.add(a);
		
		}
		
		return list;
		
	}
public List getYichuli(int idd) throws SQLException{
		
		List list =new ArrayList();
		Connection con=conn();
		Statement sta=con.createStatement();
		String dd="select * from  a_signup where userview=1 and id in ( select sid from a_userviewed  where uid= '"+idd+"')";
		ResultSet rs = sta.executeQuery(dd);
		
		while(rs.next()){
			
			String id=rs.getString("id");
			String name=rs.getString("name");
		    String createtime=rs.getString("createtime");
			String gender=rs.getString("gender");
			String userview=rs.getString("userview");
			Manager a=new Manager();
			a.setName(name);
			a.setId(id);
			a.setCreatetime(createtime);
			a.setGender(gender);
			a.setUserview(userview);
			a.setId(id);
		    list.add(a);
		
		}
		
		return list;
		
	}
	
public List select(String id1) throws SQLException{
		
		List list =new ArrayList();
		Connection con=conn();
		
		Statement sta=con.createStatement();
		ResultSet rs=sta.executeQuery("select * from a_signup where id='"+id1+"'");
		while(rs.next()){
	
		    String  choseclassid=rs.getString("choseclassid");
		    String  email=rs.getString("email");
		    String  userview=rs.getString("userview");
		    String educationbackground=rs.getString("educationbackground");
		    String  graduateuniversity=rs.getString("graduateuniversity");
            String phone=rs.getString("phone");
	        String mobile=rs.getString("mobile");
		    String name=rs.getString("name");
			String id=rs.getString("id");
			String age=rs.getString("age");
			String address=rs.getString("address");
			String qq=rs.getString("qq");
			String question=rs.getString("question");
			String gender=rs.getString("gender");
			String createtime=rs.getString("createtime");
		
			Manager a=new Manager();
			a.setName(name);
			a.setAddress(address);
			a.setAge(age);
			a.setChoseclassid(choseclassid);
			a.setCreatetime(createtime);
			a.setEmail(email);
			a.setEducationbackground(educationbackground);
			a.setGender(gender);
			a.setGraduateuniversity(graduateuniversity);
			a.setId(id);
			a.setMobile(mobile);
			a.setPhone(phone);
			a.setQq(qq);
			a.setQuestion(question);
			a.setUserview(userview);	
			a.setId(id);
		    list.add(a);
					
		}
		
		return list;
		
	}
  
  public boolean updateView(String idd,int ff) throws SQLException{
	  
	  	Connection con=conn();
		Statement sta=con.createStatement();
		boolean f=sta.execute("insert into a_userviewed(sid,uid) values('"+idd+"','"+ff+"')");
		return f;
	  
	  
	  
	  
	  
  }
	public List souSuo(String name1,String phone1,String sex,String time) throws SQLException{
		  Connection con=conn();
		Statement sta=con.createStatement();
		List list=new ArrayList();
		
		
		String  aa=" select *  from  a_signup ";
		System.out.print("###"+name1+"##shu*");
		String where=null;
		where ="  where 2>1";
		where+="   and userview=0";

		
			if(name1.length()>0){
			where+="   and name like '%"+name1+"%'";}
			if(phone1.length()>0){
				
				where+="   and phone like '%"+phone1+"%'";}
if(time.length()>0){
				
				where+="   and createtime like '%"+time+"%'";}
if(sex.length()>0){
	
	where+="   and gender like '%"+sex+"%'";}
		
		aa+=where;

	
		
		ResultSet rs=sta.executeQuery(aa);
		while(rs.next()){
	
		   String  choseclassid=rs.getString("choseclassid");
		
		  String  email=rs.getString("email");
		  String  userview=rs.getString("userview");
		
		   String educationbackground=rs.getString("educationbackground");
	
		  
	
		   String  graduateuniversity=rs.getString("graduateuniversity");
           String phone=rs.getString("phone");
	       String mobile=rs.getString("mobile");
			String name=rs.getString("name");
			String id=rs.getString("id");
			String age=rs.getString("age");
			
			String address=rs.getString("address");
			String qq=rs.getString("qq");
			String question=rs.getString("question");
			String gender=rs.getString("gender");
			String createtime=rs.getString("createtime");
		
			Manager a=new Manager();
			a.setName(name);
			a.setAddress(address);
			a.setAge(age);
			a.setChoseclassid(choseclassid);
			a.setCreatetime(createtime);
			a.setEmail(email);
			a.setEducationbackground(educationbackground);
			a.setGender(gender);
			a.setGraduateuniversity(graduateuniversity);
			a.setId(id);
			a.setMobile(mobile);
			a.setPhone(phone);
			a.setQq(qq);
			a.setQuestion(question);
			a.setUserview(userview);
			a.setId(id);
		    list.add(a);
			
			 
			
			
		}
		
		return list;
		
		
	}
	public List yisouSuo(String name1,String phone1,String sex,String time,int idd) throws SQLException{
		  Connection con=conn();
		Statement sta=con.createStatement();
		List list=new ArrayList();
		
		
		String  aa=" select *  from  a_signup ";
		System.out.print("###"+name1+"##shu*");
		String where=null;
		where ="  where 2>1  ";
		
		where+="   and userview=1 and id in ( select sid from a_userviewed  where uid= '"+idd+"')";
		
			if(name1.length()>0){
			where+="   and name like '%"+name1+"%'";}
			if(phone1.length()>0){
				
				where+="   and phone like '%"+phone1+"%'";}
if(time.length()>0){
				
				where+="   and createtime like '%"+time+"%'";}
if(sex.length()>0){
	
	where+="   and gender like '%"+sex+"%'";}
		
		aa+=where;

	
		
		ResultSet rs=sta.executeQuery(aa);
		while(rs.next()){
	
		   String  choseclassid=rs.getString("choseclassid");
		
		  String  email=rs.getString("email");
		  String  userview=rs.getString("userview");
		
		   String educationbackground=rs.getString("educationbackground");
	
		  
	
		   String  graduateuniversity=rs.getString("graduateuniversity");
         String phone=rs.getString("phone");
	       String mobile=rs.getString("mobile");
			String name=rs.getString("name");
			String id=rs.getString("id");
			String age=rs.getString("age");
			
			String address=rs.getString("address");
			String qq=rs.getString("qq");
			String question=rs.getString("question");
			String gender=rs.getString("gender");
			String createtime=rs.getString("createtime");
		
			Manager a=new Manager();
			a.setName(name);
			a.setAddress(address);
			a.setAge(age);
			a.setChoseclassid(choseclassid);
			a.setCreatetime(createtime);
			a.setEmail(email);
			a.setEducationbackground(educationbackground);
			a.setGender(gender);
			a.setGraduateuniversity(graduateuniversity);
			a.setId(id);
			a.setMobile(mobile);
			a.setPhone(phone);
			a.setQq(qq);
			a.setQuestion(question);
			a.setUserview(userview);
			a.setId(id);
		    list.add(a);
			
			 
			
			
		}
		
		return list;
		
		
	}
	public boolean insert(String name,String password,String age,String address) throws SQLException{
		
		
		Connection con=conn();
		
		Statement sta=con.createStatement();
		boolean ff=sta.execute("insert into zhuce1 ( name, password, age, address) values ('"+name+"','"+password+"','"+age+"','"+address+"')");
		return ff;
	}
	public boolean insert1(String id,String name,String password,String age,String address) throws SQLException{
		
		
		Connection con=conn();
		
		Statement sta=con.createStatement();
		boolean ff=sta.execute("update zhuce1 set name='"+name+"', password='"+password+"', age='"+age+"', address='"+address+"'  where id='"+id+"'");
		return ff;
	}
	public boolean updateId(String idd) throws SQLException{
		
		Connection con=conn();
		Statement sta=con.createStatement();
		boolean f=sta.execute("update a_signup set userview=1 where id='"+idd+"'");
		return f;
		
	}
    public List chaZhao(String name1,String password1) throws SQLException{
    	Connection con=conn();
    	List list =new ArrayList();
    	Statement sta=con.createStatement();
    	ResultSet rs=sta.executeQuery("Select * from zhuce1 where name='"+name1+"' and password='"+password1+"'");
    	while(rs.next()){
    		
    		String name=rs.getString("name");
			//String count=rs.getString("count");
			String id=rs.getString("id");
			String age=rs.getString("age");
			String password=rs.getString("password");
			String address=rs.getString("address");
			Manager a=new Manager();
			a.setName(name);
			a.setAddress(address);
			a.setAge(age);
			a.setPassword(password);
			//a.setCount(count);
			a.setId(id);
		    list.add(a);
    		
    		
    	}
    	return list;
    }
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getUserview() {
		return userview;
	}

	public void setUserview(String userview) {
		this.userview = userview;
	}

	public String getCreatetime() {
		return createtime;
	}

	public void setCreatetime(String createtime) {
		this.createtime = createtime;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getChoseclassid() {
		return choseclassid;
	}

	public void setChoseclassid(String choseclassid) {
		this.choseclassid = choseclassid;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEducationbackground() {
		return educationbackground;
	}

	public void setEducationbackground(String educationbackground) {
		this.educationbackground = educationbackground;
	}


	public String getGraduateuniversity() {
		return graduateuniversity;
	}

	public void setGraduateuniversity(String graduateuniversity) {
		this.graduateuniversity = graduateuniversity;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getQuestion() {
		return question;
	}

	public void setQuestion(String question) {
		this.question = question;
	}

	public String getAuth() {
		return auth;
	}

	public void setAuth(String auth) {
		this.auth = auth;
	}
	

}
